<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> 
<head>
<%@ include file="../../include/easyui.jsp" %>
<%@ include file="../../include/pForm.jsp" %>
<%@ include file="/WEB-INF/jsp/include/easyui-layui-upload.jsp" %>
<script src="/plug-in/jquery-easyui-1.5.1/plugins/jquery.choosebox.js"></script>
<title>支出流程启动页面</title>
<script>
	$(function(){
		fn.resetForm();
		var _data = fn.getDialogData();
		
		fn.readOnly();
		var rn = '${param.rn}';
		if(rn){
			$('#status').combobox('readonly', false);	// 禁用只读模式
			$("#msg").textbox("readonly",false);
			$.messager.show({ title:'我的消息', msg: '请填写审批结果及审批建议！',timeout:3000, showType:'slide' });
		}
		
		$("#dataGrid").datagrid({
			idField: "id",
			rownumbers: true,
			pagination: true,
			singleSelect: true, 
			showFooter: true,
			url : '/console/com.fs.jzzn.pojo.ExpenseItem/list',
			queryParams: {
				expenseNo :_data.expenseNo,
				expenseNo_searchType: "eq"
			},
			fitColumns:true,
			nowrap:false,
			columns : [[
				{field: 'costUser', title: '支出对象', width: 80,editor:{
					 type:'combobox',
						options:{
							method:'get',
							url:'/console/combobox?valueField=nickName&textField=nickName&modleName=user',
							required:true
						}
				}}
				,{field: 'remark', title: '标题说明', width: 200,editor:{
						type: 'textbox',
						options:{
							required:true,
							validType:['length[0,500]']
						}
				}}
				,{field: 'costType', title: '类别', width: 80,editor:{
					type:'combobox',
					options:{
						method:'get',
						url:'/console/combobox?valueField=dicName&textField=dicName&modleName=dictionary&pCode=B1&pCode_searchType=eq',
						required:true
					}
				}}
				,{field: 'money', title: '金额(元)', width: 80,editor:{type:'numberbox',options:{precision:2,required:true}}}
				,{field: 'billsNo', title: '凭单号', width: 100,editor:'textbox'}
				,{field: 'pNo', title: '路段编号', width: 90,editor:{
					type:'combobox',
					options:{
						method:'get',
						url:'/console/combobox?valueField=pNo&textField=pRoad&modleName=project'
					}
				}}
				,{field: 'department', title: '关联项目部', width: 130,editor:{
					type:'combobox',
					options:{
						method:'get',
						url:'/console/combobox?valueField=dicName&textField=dicName&modleName=dictionary&pCode=A5&pCode_searchType=eq'
					}
				}}
				,{field: 'costDate', title: '日期', width: 100,editor:{
					type:'datebox'
				}}
			]],
			onLoadSuccess:function(){
				childTotal();
			},
			onAfterEdit:function(index, row, changes){
				$.each(['remark','costType','billNo'], function (i,item) {
					$("td[field="+ item +"] div").tooltip({ content: function(){ return $(this).text(); } });
				});
				childTotal();
			}
		});
		
		/*表单提交前动作*/
		fn.onBeforeSubmitForm = function(){
			var rows = $("#dataGrid").datagrid('getRows') ;
			$("input[name=childJson]").val(JSON.stringify(rows));
		}
		
		setTimeout(function(){
			//$("label[for=_easyui_textbox_input6]").css({"line-height":"60px"});
			//$("label[for=_easyui_textbox_input7]").css({"line-height":"60px"});
		},100);
		
		/*流程启动，下个环节处理人选择*/
		$.getJSON('/console/com.fs.jzzn.pojo.TaskCandidateUsers/json', {
			processKey:'Expense',processKey_searchType:'eq',taskId:'usertask1',taskId_searchType:'eq'
		}, function(json){
			if(json && json.candidateUsers){
				var comboData = [];
				var candidateUsers = json.candidateUsers.split(",");
				for(var i=0;i<candidateUsers.length;i++){
					comboData.push({id: i, text: candidateUsers[i] });
				}
				$('#inputUser').combobox('loadData', comboData);

			}
		});
	});
	
	function childTotal(){
		var dData = $('#dataGrid').datagrid('getData');
		var total = {money: 0, costType: '合计：'};
		$.each(dData.rows ||[], function (i,item) {
			total.money += parseFloat(item.money || '0');
		});
		total.money = total.money.toFixed(2);
		$('#dataGrid').datagrid('reloadFooter',[ total ]);
	}
	
	function deleteRow(index){
		$("#dataGrid").datagrid('deleteRow',index) ;
	}
</script>
</head>
<body>
	<div class="easyui-panel" data-options="fit:true,border:false" style="padding:10px;width:100%;">
		<!-- 替换自动form表单 -->
		<form id="easyuiForm" method="post" action="/console/expense/rewrite/start" style="min-width: 800px;width:100%;"   >
		 <!--类名属性及默认主键id-->
		 <input type="hidden" name="className" value="com.fs.jzzn.pojo.Expense" />
		 <input type="hidden" name="createrId" value="${SESSION_USER.user.id}" />
		 <input type="hidden" name="childJson" value="[]" >
		 <input type="hidden" name="id" value="" />
		 <input type="hidden" name="processInstanceId" value="" />
		 
		<div style="margin-bottom:20px">
		  	<input  class="easyui-textbox"  name="expenseNo" style="width:260px;" readonly="readonly" data-options="label:'单据编号:',required:true,prefix:'ZC',timestamp:'yyMMddHHmmss' "/>
		  	<input class="easyui-textbox easyui-validatebox" id="applyDate" name="applyDate" style="width:260px;" data-options="label:'申请日期:',required:true" />
		  	<input class="easyui-textbox easyui-validatebox" name="pm"  value="${SESSION_USER.user.nickName}" style="width:260px;" data-options="label:'申请人:',required:true,validType:'length[0,15]'" />
		 </div>
		 
		   <div style="margin-bottom:20px">
		 		<input class="easyui-textbox"   name="department" style="width:260px;" data-options="label:'关联项目部:',required:false" />
		    	<input class="easyui-textbox" name="contractName" style="width:520px;" data-options="label:'合同名称:'" />
		  	</div>
		 	
		 	 <div style="margin-bottom:20px">
		 	 	<input class="easyui-textbox easyui-validatebox" name="remark" multiline="true" style="width:780px;height:60px;" data-options="label:'备注:',required:false,validType:'length[0,500]'" />
		 	 </div>
			 
			 <!-- 
			 <div style="margin-bottom:20px">
			 	<input class="easyui-layuiupload" name="attachment" style="width:100%;" data-options="label:'附件:',upload:{auto:false,height:150,readonly:true}" />
			 </div>
			  -->
			 
			 <div style="margin-bottom:20px">
		 		<input class="easyui-layuiupload" name="attachment" style="width:780px;" data-options="label:'附件:',upload:{auto:false,height:250,readonly:true}" />
		 	</div>
		 
		 
		 <!-- 支付明细 -->
		 <div style="margin-bottom:20px;margin-left: 80px;">
				<table id="dataGrid" title="支付明细" style="height:260px;width:80%;"></table>
			</div>
		</form>
	</div>
</body>
</html>